package com.xsl.dao.impl;

import com.xsl.dao.ChatHistoryDao;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component  //将当前对象交给spring容器管理
public class ChatHistoryDaoImpl implements ChatHistoryDao {
    // 模拟数据库
    // key: 业务类型，value: 所有历史会话ID列表
    private Map<String,List<String>> map = new HashMap<>();

    @Override
    public void sava(String type, String chatId) {
        if(map.containsKey(type)){//已经包含这个type
            List<String> list = map.get(type);
            if(!list.contains(chatId)){
                list.add(chatId);
            }
        }else {
            List<String> list = new ArrayList<>();
            list.add(chatId);
            map.put(type,list);
        }
    }
    @Override
    public List<String> fetchChatHistory(String type) {
        List<String> list = map.get(type);
        if(list == null){
            list = new ArrayList<>();
        }
        return list;
    }
}
